package com.lagou.response;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ResponseResult<T> {

    private Boolean success;

    private Integer state;

    private String message;

    private T content;

    private static final String SUCCESS = "success";

    private static final String FAIL = "fail";

    public static <T> ResponseResult<T> success() {
        ResponseResult<T> result = new ResponseResult<>();
        result.setSuccess(Boolean.TRUE);
        result.setMessage(SUCCESS);
        result.setState(200);
        return result;
    }

    public static <T> ResponseResult<T> success(T content) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setSuccess(Boolean.TRUE);
        result.setMessage(SUCCESS);
        result.setContent(content);
        result.setState(200);
        return result;
    }

    public static <T> ResponseResult<T> fail() {
        ResponseResult<T> result = new ResponseResult<>();
        result.setSuccess(Boolean.FALSE);
        result.setMessage(FAIL);
        result.setState(400);
        return result;
    }

    public static <T> ResponseResult<T> fail(T content) {
        ResponseResult<T> result = new ResponseResult<>();
        result.setSuccess(Boolean.FALSE);
        result.setMessage(FAIL);
        result.setContent(content);
        result.setState(400);
        return result;
    }

}
